import 'package:flutter/material.dart';
import 'package:flutter_module/login/userInfo.dart';
import 'tabbar/tabbarWidget.dart';
import 'package:provider/provider.dart';
import 'tabbar/tabBarProvider.dart';
import 'tabbar/profileProvider.dart';
import 'tabbar/routers/application.dart';
import 'package:fluro/fluro.dart';
import 'tabbar/routers/Routes.dart';
import 'login/login_screen.dart';
import 'tool/userManager.dart';
import 'tool/fileManager.dart';
import 'tabbar/shop/shopScreenProvider.dart';

void main() {
  realRunApp();
}

void realRunApp() async {

  // 如果在runApp之前要异步操作,则必须调用这段代码
  WidgetsFlutterBinding.ensureInitialized();

  Provider.debugCheckInvalidValueType = null;
  UserInfo userInfo = await FileManager.getUserInfo();
  UserManager manager = UserManager();
  manager.userInfo = userInfo;

  runApp(MultiProvider(providers: [
      ChangeNotifierProvider.value(value: TabBarProvider()),
      ChangeNotifierProvider.value(value: ProfileProvider()),
      ChangeNotifierProvider.value(value: ShopScreenProvider()),
    ],
    child: MyApp()
  ));
}

class MyApp extends StatelessWidget  {
  const MyApp({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context)  {

    final router = Router();
    Routes.configureRouters(router);
    Application.router = router;

    return MaterialApp(
      title: '导航栏',
      theme: ThemeData(
        primaryColor: Color.fromRGBO(46, 137, 250, 1)
      ),
      // home: UserManager().userInfo == null ?  LoginScreen() : TabBarWidget(),
      home: LoginScreen(),
    );
  }


}
